package fr.upmc.tps.mdoc.tools;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import fr.upmc.tps.mdoc.models.IContact;

public class ContactAspect {
	
	public static String capitalize(String content){
		Pattern capitalize = Pattern.compile("([\\?!\\.] )([a-z])");
		Matcher m = capitalize.matcher(content);
		while (m.find()) {
			content = m.replaceFirst(m.group(1) + m.group(2).toUpperCase());
			m = capitalize.matcher(content);
		}
		return content;
	}
	
	public IContact capitalize(IContact contact) {

		contact.setLastName(contact.getLastName().toUpperCase());
		contact.setFirstName(capitalize(contact.getFirstName().toLowerCase()));
		
		return contact;
		
	}

	public void addContact(IContact contact) {
		System.err.println("Aspect add contact : capitalize");
		capitalize(contact);
	}
	
	public void updateContact(final IContact contact) {
		System.err.println("Aspect update contact : capitalize");
		capitalize(contact);
	}
	
}
